package cn.cloudplug.friendsrecommend;

import java.util.Calendar;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.PopupMenu;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.PopupMenu.OnMenuItemClickListener;
import cn.cloudplug.friendsrecommend.R;

public class PersonalSignActivity extends Activity implements OnClickListener{
	private String[] countries;
	private RadioGroup rg_gender;
	private EditText et_my_name;
	private EditText et_my_ID_Card;
	private EditText et_tall;
	private EditText et_medical_order;
	private TextView tv_country;
	private TextView tv_born_year;
	private TextView tv_born_month;
	private TextView tv_born_day;
	private int year,month,day;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sign_personal);
		setView();
	}
	private void setView() {
		countries=getResources().getStringArray(R.array.country);
		Calendar c=Calendar.getInstance();
		year=c.get(Calendar.YEAR);month=c.get(Calendar.MONTH)+1;day=c.get(Calendar.DAY_OF_MONTH);
		ViewGroup vp=(ViewGroup) findViewById(R.id.title);
		vp.findViewById(R.id.iv_home).setOnClickListener(this);
		et_my_name=(EditText) findViewById(R.id.et_my_name);
		et_my_ID_Card=(EditText) findViewById(R.id.et_my_ID_Card);
		et_tall=(EditText) findViewById(R.id.et_tall);
		et_medical_order=(EditText) findViewById(R.id.et_medical_order);
		tv_country=(TextView) findViewById(R.id.tv_country);
		tv_born_year=(TextView) findViewById(R.id.tv_born_year);
		tv_born_month=(TextView) findViewById(R.id.tv_born_month);
		tv_born_day=(TextView) findViewById(R.id.tv_born_day);
		findViewById(R.id.btn_next).setOnClickListener(this);
		tv_country.setOnClickListener(this);
		tv_born_year.setOnClickListener(this);
		tv_born_month.setOnClickListener(this);
		tv_born_day.setOnClickListener(this);
		updateUI();
	}
	@Override
	public void onClick(View v) {
	switch (v.getId()) {
	case R.id.btn_next:
		startActivity(PersnalSignProInfoActivity.class);
		break;
	case R.id.iv_home:
		startActivity(MainActivity.class);
		break;
	case R.id.tv_country:
		showCountry();
		break;
	case R.id.tv_born_year:
		showDatePicker();
		break;
	case R.id.tv_born_month:
		showDatePicker();
		break;
	case R.id.tv_born_day:
		showDatePicker();
		break;
	}
		
	}

	private void showCountry() {
		AlertDialog.Builder builder = new Builder(PersonalSignActivity.this);
		
        builder.setItems(countries, new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface arg0, int arg1)
            {
                // TODO 自动生成的方法存根
                System.out.println(arg1);
               tv_country.setText(countries[arg1]);
                arg0.dismiss();
            }
        });
        AlertDialog dialog=builder.create();
        dialog.getWindow().setLayout(300, 400);
        dialog.show();
		
	}
	private void showDatePicker() {
		new DatePickerDialog(this, new OnDateSetListener() {
			@Override
			public void onDateSet(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				PersonalSignActivity.this.year=year;
				PersonalSignActivity.this.month=monthOfYear;
				PersonalSignActivity.this.day=dayOfMonth;
				updateUI();
			}
		}, year, month, day).show();
	}
	protected void updateUI() {
		tv_born_year.setText(year+"");
		tv_born_month.setText(month+"");
		tv_born_day.setText(day+"");
	}
	private void startActivity(Class<?> clz) {
		startActivity(new Intent(this,clz));
	}
	
}
